<!--
 * @Description: 
 * @Version: 1.0
 * @Author: wen shukai
 * @Date: 2022-06-16 15:46:49
 * @LastEditTime: 2022-06-16 16:23:00
 * @LastEditors: wen shukai
 * @FilePath: \self-taught-js\TheBinding.html
-->
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <input type="text" v-mode="title">
    <input type="text" v-mode="title">
    <div v-bind="title"></div>
</body>
<script>
    function View() {
        //设置代理拦截
        let proxy = new Proxy(
            {}, {
            get(obj, property) { 
                console.log(obj,'44')
                console.log(property,'555')
            },
            set(obj, property, value) {
                console.log(obj,'111');
                console.log(property,'222');
                console.log(value,'333');
                obj[property] = value;
                document.querySelectorAll(`[v-mode="${property}"],[v-bind="${property}"]`).forEach(m => {
                    console.log(m,'666')
                    m.innerHTML = value;
                    m.value = value
                })
            }
        }
        );
        //初始化绑定元素事件
        this.run = function(){
            const els = document.querySelectorAll("[v-mode]")
            console.log(els,'777')
            els.forEach(item=>{
                item.addEventListener("keyup",function(){
                    console.log('888')
                    proxy[this.getAttribute("v-mode")]= this.value
                })
            })
        }
    }
    let view = new View().run()
</script>

</html>